home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Magazin/MacEasy 25
/
Mac Magazin and MacEasy Magazine CD - Issue 25.iso
/
Online
/
Joe's-PPP-Scripts
/
PPP-plan-toggle
/
PPP-plan-toggle-as text
< prev
next >
Wrap
Text File
|
1996-08-21
|
5KB
|
163 lines
property openPlan : {""}
property closePlan : {""}
global planFile, parsedPlanfile
global planDialogtext, planFilelocation, intermediateResult
on run
if openPlan = {""} then
set planDialogtext to {"Select a file to be sent at OPEN connection:"}
getPlanlocation()
set openPlan to planFilelocation
end if
if closePlan = {""} then
set planDialogtext to {"Select a file to be sent at CLOSE connection:"}
getPlanlocation()
set closePlan to planFilelocation
end if
if (PPPopened) then
set planFile to {""}
open for access file closePlan
set planFile to (read closePlan)
close access closePlan
dealwithPlanfile()
ftpPlanfile()
closePPP with hard close
else
openPPP (getPPPServer)
set planFile to {""}
open for access file openPlan
set planFile to (read openPlan)
close access openPlan
repeat while not (PPPopened)
end repeat
dealwithPlanfile()
ftpPlanfile()
end if
end run
on getPlanlocation()
try
set planFilelocation to (choose file with prompt ¬
planDialogtext of type {"TEXT"}) as string
on error errMsg
abort()
end try
end getPlanlocation
on dealwithPlanfile()
try
searchReplace of me into planFile at "%ip%" given replaceString:(tcp my address)
set intermediateResult to result as text
on error errMsg
abort()
end try
try
searchReplace of me into intermediateResult at "%clock%" given replaceString:(current date)
set parsedPlanfile to result as text
on error errMsg
abort()
end try
end dealwithPlanfile
on searchReplace into mainString at searchString given replaceString:replaceString
repeat while mainString contains searchString
set foundOffset to offset of searchString in mainString
set stringStart to text 1 thru (foundOffset - 1) of mainString
set stringEnd to text (foundOffset + (count of searchString)) thru -1 of mainString
set mainString to stringStart & replaceString & stringEnd
end repeat
return mainString
end searchReplace
on ftpPlanfile()
set LF to (ASCII character of 10)
set CR to (ASCII character of 13)
set CRLF to CR & LF
try
set oldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"."}
set localAddr to (tcp my address)
set localAddrList to text items of localAddr
set AppleScript's text item delimiters to {","}
set localAddrCommaString to localAddrList as string
set AppleScript's text item delimiters to oldDelimiters
set sss to (tcp connect to host (GetICPreference ftp host) port 21)
try
readresponse(sss)
tcp write stream sss data "USER " & (GetICPreference mail account) & return using ISO88591
readresponse(sss)
tcp write stream sss data "PASS " & (GetICPreference mail password) & return using ISO88591
readresponse(sss)
tcp write stream sss data "TYPE A" & return using ISO88591
readresponse(sss)
set data_stream to (tcp wait for connect)
set data_stream_status to (tcp status stream data_stream)
set portHiByte to round (local port of data_stream_status) / 256 rounding down
set portLoByte to (local port of data_stream_status) mod 256
tcp write stream sss data "PORT " & localAddrCommaString & "," & portHiByte & "," & portLoByte & return using ISO88591
readresponse(sss)
tcp write stream sss data "STOR .plan" & return & LF
readresponse(sss)
repeat until (connection status of (tcp status stream data_stream) = Connected)
end repeat
tcp write stream data_stream data parsedPlanfile using ISO88591
try
on error msg number num from obj partial result pr
tcp close stream data_stream
error msg number num from data_stream
end try
tcp close stream data_stream
readresponse(sss)
tcp write stream sss data "QUIT" & return using ISO88591
readresponse(sss)
tcp close stream sss
on error msg number num from obj partial result pr
try
tcp write stream sss data "QUIT" & return using ISO88591
readresponse(sss)
on error
end try
tcp close stream sss
error msg number num from obj partial result pr
end try
on error errMsg
abort()
end try
end ftpPlanfile
on readresponse(sstream)
set LF to ASCII character (10)
repeat until (tcp ahead characters LF stream sstream)
end repeat
set serverResponse to (tcp read until characters LF stream sstream using ISO88591)
end readresponse
on abort()
display dialog "Plan upload script aborted" buttons {"OK"} default button "OK"
set openPlan to {""}
set closePlan to {""}
quit
end abort
on quit
continue quit
end quit